package com.zjj.lbw.algorithm.example;

/**
 * @author zhanglei.zjj
 * @description 大O分析法示例程序
 * @date 2023/3/11 17:05
 */
public class BigOAnalysis {
    public int exampleMethod1(int n) {
        int j = 4;
        for (int i = 1; i < n; i++) {
            j = j * i;
        }

        return j;
    }

    public int exampleMethod2(int n) {
        int j = 4;
        for (int i = 1; i < n; i++) {
            for (int i1 = 0; i1 < n; i1++) {
                j = j * i + i1;
            }
        }

        return j;
    }

    public int exampleMethod3(int n) {
        int sum_1 = 0;
        for (int p = 1; p < 100; ++p) {
            sum_1 = sum_1 + p;
        }
        int sum_2 = 0;
        for (int q = 1; q < n; ++q) {
            sum_2 = sum_2 + q;
        }
        int sum_3 = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                sum_3 = sum_3 + i * j;
            }
        }
        return sum_1 + sum_2 + sum_3;
    }

    public void exampleMethod4(int n) {
        int j =2;
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (i + 1) * j;
        }
    }


}
